//
//  ActDetailView.m
//  TravelFirst
//
//  Created by lanou3g on 15/9/21.
//  Copyright (c) 2015年 吴娅君. All rights reserved.
//

#import "ActDetailView.h"
#define kW frame.size.width
#define kH frame.size.height
#define kY frame.origin.y

@implementation ActDetailView

- (instancetype)initWithFrame:(CGRect)frame target:(id)target action:(SEL)action heightTitle:(CGFloat)title address:(CGFloat)address actLable:(CGFloat)ActLable detailDate:(CGFloat)detailDate fen:(NSMutableArray *)fenArr requirement:(CGFloat)requirement moneyDetail1:(CGFloat)detail1 knowDetail:(CGFloat)knowDetail date:(NSNumber *)date arr:(NSArray *)arr detailArr:(NSMutableArray *)detailArr{
    self = [super initWithFrame:frame];
    if(self){
        UIScrollView *view = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
        
        
        self.title = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, kWidth - 20, title)];
        //设置自动行数与字符换行
        _title.numberOfLines=0;
        _title.font = [UIFont boldSystemFontOfSize:20];
        _title.lineBreakMode = NSLineBreakByWordWrapping;
        //_title.backgroundColor = [UIColor redColor];
        
        self.logo = [[UIImageView alloc] initWithFrame:CGRectMake(10, self.title.kH + 20, 30, 30)];
        //_logo.backgroundColor = [UIColor orangeColor];
        
        self.logoTitle = [[UILabel alloc] initWithFrame:CGRectMake(50, self.title.kH + 20, 200, 30)];
        //_logoTitle.backgroundColor = [UIColor yellowColor];
        
        UIScrollView *picView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, self.logoTitle.kH + 20  +self.logoTitle.kY, kWidth, 80)];
        picView.contentSize = CGSizeMake(3 * kWidth, 80);
        picView.backgroundColor = [UIColor whiteColor];
        
        for(int i = 0;i < arr.count; i++){
            TapImageView *pic = [[TapImageView alloc] initWithFrame:CGRectMake(i * (kWidth /5) + 5 , 0, (kWidth - 30)/5, 80) taget:target action:action];
            //pic.backgroundColor = [UIColor magentaColor];
            pic.tag = 200 + i;
            [picView addSubview:pic];
        }
        if(arr.count==0){
            picView.frame=CGRectMake(0, self.logoTitle.kH+self.logoTitle.kY, kWidth, 0);
        }
        UILabel *time = [[UILabel alloc] initWithFrame:CGRectMake(10, picView.kY + picView.kH + 20, 80, 30)];
        time.text = @"活动时间:";
        [self setText:time];
        
        self.ActTime = [[UILabel alloc] initWithFrame:CGRectMake(100, picView.kY + picView.kH + 20, 200, 30)];
        //_ActTime.backgroundColor = [UIColor greenColor];
        
        UILabel *day = [[UILabel alloc] initWithFrame:CGRectMake(10, time.kY + time.kH + 10, 80, 30)];
        day.text = @"活动天数:";
        [self setText:day];
        
        self.ActDay = [[UILabel alloc] initWithFrame:CGRectMake(100, time.kY + time.kH + 10, 200, 30)];
        //_ActDay.backgroundColor = [UIColor greenColor];
        
        UILabel *add = [[UILabel alloc] initWithFrame:CGRectMake(10, day.kY + day.kH + 10, 80, 30)];
        add.text = @"活动地点:";
        [self setText:add];
        
        self.ActAddress = [[UILabel alloc] initWithFrame:CGRectMake(100, day.kY + day.kH + 10, 200, 30)];
        //_ActAddress.backgroundColor = [UIColor greenColor];
        
        UILabel *actty = [[UILabel alloc] initWithFrame:CGRectMake(10, add.kY + add.kH + 10, 80, 30)];
        actty.text = @"活动类型:";
        [self setText:actty];
        
        self.ActType = [[UILabel alloc] initWithFrame:CGRectMake(100, add.kY + add.kH + 10, 200, 30)];
        //_ActType.backgroundColor = [UIColor greenColor];
        
        UILabel *hotel = [[UILabel alloc] initWithFrame:CGRectMake(10, actty.kY + actty.kH + 10, 80, 30)];
        hotel.text = @"住宿方式:";
        [self setText:hotel];
        
        self.HotelType = [[UILabel alloc] initWithFrame:CGRectMake(100, actty.kY + actty.kH + 10, 200, 30)];
        //_HotelType.backgroundColor = [UIColor greenColor];
        
        UILabel *cost = [[UILabel alloc] initWithFrame:CGRectMake(10, hotel.kY + hotel.kH + 10, 80, 30)];
        cost.text = @"活动费用:";
        [self setText:cost];
        
        self.ActCost = [[UILabel alloc] initWithFrame:CGRectMake(100, hotel.kY + hotel.kH + 10, 200, 30)];
        //_ActCost.backgroundColor = [UIColor greenColor];
        
        UILabel *place = [[UILabel alloc] initWithFrame:CGRectMake(10, cost.kY + cost.kH + 10, 80, 30)];
        place.text = @"集合地点:";
        [self setText:place];
        
        self.ActPlace = [[UILabel alloc] initWithFrame:CGRectMake(100, cost.kY + cost.kH + 15, 200, address)];
        _ActPlace.font = [UIFont systemFontOfSize:17];
        _ActPlace.numberOfLines = 0;
        //_ActPlace.backgroundColor = [UIColor greenColor];
        
        UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(10, self.ActPlace.kY + self.ActPlace.kH +20, 100, 30)];
        lab.text = @"活动亮点";
        lab.font = [UIFont boldSystemFontOfSize:20];
        
        UIView *vi = [[UIView alloc] initWithFrame:CGRectMake(100, self.ActPlace.kY + self.ActPlace.kH +35, kWidth - 115, 1)];
        vi.backgroundColor = [UIColor blackColor];
        
        self.ActLable = [[UILabel alloc] initWithFrame:CGRectMake(10, lab.kY + lab.kH + 15, kWidth - 20, ActLable)];
        _ActLable.numberOfLines = 0;
        _ActLable.font = [UIFont systemFontOfSize:14];
        _ActLable.lineBreakMode = NSLineBreakByCharWrapping;
        
        
        UILabel *detail = [[UILabel alloc] initWithFrame:CGRectMake(10, self.ActLable.kH + self.ActLable.kY +20, 100, 30)];
        detail.text = @"详细行程";
        detail.font = [UIFont boldSystemFontOfSize:20];
        
        UIView *de = [[UIView alloc] initWithFrame:CGRectMake(100, self.ActLable.kY + self.ActLable.kH +35, kWidth - 115, 1)];
        de.backgroundColor = [UIColor blackColor];
        

        self.detailDate = [[UIView alloc] initWithFrame:CGRectMake(10, detail.kH + detail.kY + 15, kWidth - 20, detailDate)];
        
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(35.5, 8, 1, detailDate - 22)];
        line.backgroundColor = [UIColor grayColor];
        [self.detailDate addSubview:line];
        
        float t = 0.0;
        for( int i=0;i<fenArr.count;i++){
            if (i==0) {
                t=0;
            }else{
                t += [fenArr[i-1] floatValue];
                t+=30;
            }
            UILabel *img=[[UILabel alloc]initWithFrame:CGRectMake(30, t, 78, 25)];
            img.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_day_activity_79x24@2x"]];
            img.font=[UIFont boldSystemFontOfSize:14];
            img.textColor=[UIColor whiteColor];
            img.text=[NSString stringWithFormat:@"       DAY %d",i+1];
            [_detailDate addSubview:img];
            
            UILabel *detaillab=[[UILabel alloc]initWithFrame:CGRectMake(50, t+30, kWidth - 120, [fenArr[i] floatValue])];
            [_detailDate addSubview:detaillab];
            float vtemp=0.0;
            for (int j=0;j<[detailArr[i] count];j++) {
                NSMutableDictionary *v=detailArr[i][j];
                if (j==0) {
                    vtemp=0;
                }else{
                    vtemp += [detailArr[i][j-1][@"height"] floatValue]+10;
                }
                UILabel *l=[[UILabel alloc]initWithFrame:CGRectMake(0, vtemp, kWidth-120, [v[@"height"] floatValue]+1)];
                l.text=v[@"content"];
                l.font=[UIFont boldSystemFontOfSize:14];
                l.numberOfLines=0;
                l.lineBreakMode = NSLineBreakByCharWrapping;
                [detaillab addSubview:l];
                UILabel *time=[[UILabel alloc]initWithFrame:CGRectMake(-52, vtemp, 50, 20)];
                time.text=@"          ●";
                if(![v[@"start_time"] isEqualToString:@"00:00"]){
                    time.text=[NSString stringWithFormat:@"%@ ●",v[@"start_time"]];
                }
                time.font=[UIFont boldSystemFontOfSize:12];
                [detaillab addSubview:time];
            }
        }
        
        
        UILabel *aa = [[UILabel alloc] initWithFrame:CGRectMake(10, _detailDate.kH + _detailDate.kY +20, 100, 30)];
        aa.text = @"装备要求";
        aa.font = [UIFont boldSystemFontOfSize:20];
        
        UIView *aa1 = [[UIView alloc] initWithFrame:CGRectMake(100, _detailDate.kY + _detailDate.kH +35, kWidth - 115, 1)];
        aa1.backgroundColor = [UIColor blackColor];
        
        self.Requirement = [[UILabel alloc] initWithFrame:CGRectMake(10, aa.kH +aa.kY + 15, kWidth - 20, requirement)];
        _Requirement.numberOfLines = 0;
        _Requirement.font = [UIFont systemFontOfSize:14];
        _Requirement.lineBreakMode = NSLineBreakByCharWrapping;
        
        
        UILabel *bb = [[UILabel alloc] initWithFrame:CGRectMake(10, self.Requirement.kH + self.Requirement.kY +20, 100, 30)];
        bb.text = @"费用详情";
        bb.font = [UIFont boldSystemFontOfSize:20];
        
        UIView *bb1 = [[UIView alloc] initWithFrame:CGRectMake(100, self.Requirement.kY + self.Requirement.kH +35, kWidth - 115, 1)];
        bb1.backgroundColor = [UIColor blackColor];
        
        self.moneyDetail1 = [[UILabel alloc] initWithFrame:CGRectMake(10, bb.kH + bb.kY + 15, kWidth - 20, detail1)];
        _moneyDetail1.numberOfLines = 0;
         _moneyDetail1.font = [UIFont systemFontOfSize:14];
        _moneyDetail1.lineBreakMode = NSLineBreakByCharWrapping;
        
        
        UILabel *cc = [[UILabel alloc] initWithFrame:CGRectMake(10, self.moneyDetail1.kH + self.moneyDetail1.kY +20, 100, 30)];
        cc.text = @"报名须知";
        cc.font = [UIFont boldSystemFontOfSize:20];
        
        UIView *cc1 = [[UIView alloc] initWithFrame:CGRectMake(100, self.moneyDetail1.kY + self.moneyDetail1.kH +35, kWidth - 115, 1)];
        cc1.backgroundColor = [UIColor blackColor];
        
        self.knowDetail = [[UILabel alloc] initWithFrame:CGRectMake(10, cc.kH + cc.kY + 15, kWidth - 20, knowDetail)];
        _knowDetail.numberOfLines = 0;
        _knowDetail.font = [UIFont systemFontOfSize:14];
        _knowDetail.lineBreakMode = NSLineBreakByCharWrapping;
        
        UIView *clock = [[UIView alloc] initWithFrame:CGRectMake(0, kHeight - 120, kWidth, 60)];
        clock.backgroundColor = [UIColor blackColor];
        
        NSArray *arr1 = @[@"咨询",@"收藏",@"报名"];
        NSArray *arr2 = @[@"icon_call_pressed_24x24@2x",@"icon_fav_pressed_24x24@2x",@"icon_apply_pressed_24x24@2x"];
        for (int i = 0; i < 3; i++) {
            UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(i *(kWidth/3), 0, kWidth/3, 60)];
            button.tag = 600+i;
            [clock addSubview:button];
            
            UIImageView *pi = [[UIImageView alloc] initWithFrame:CGRectMake(35, 15, button.kW/4.5, 25)];
            pi.image = [UIImage imageNamed:arr2[i]];
            UILabel *text = [[UILabel alloc] initWithFrame:CGRectMake(button.kW/2, 0, button.kW/2, 60)];
            text.textColor = [UIColor whiteColor];
            text.text = arr1[i];
            
            [button addSubview:pi];
            [button addSubview:text];
        }
        
        
        [view addSubview:_title];
        [view addSubview:_logo];
        [view addSubview:_logoTitle];
        [view addSubview:picView];
        [view addSubview:time];
        [view addSubview:_ActTime];
        [view addSubview:_ActDay];
        [view addSubview:_ActAddress];
        [view addSubview:_ActType];
        [view addSubview:_HotelType];
        [view addSubview:_ActCost];
        [view addSubview:_ActPlace];
        [view addSubview:_ActLable];
        [view addSubview:_detailDate];
        [view addSubview:_Requirement];
        [view addSubview:_moneyDetail1];
        
        [view addSubview:_knowDetail];
        [view addSubview:day];
        [view addSubview:add];
        [view addSubview:actty];
        [view addSubview:hotel];
        [view addSubview:cost];
        [view addSubview:place];
        [view addSubview:vi];
        [view addSubview:detail];
        [view addSubview:de];
        [view addSubview:aa];
        [view addSubview:aa1];
        [view addSubview:bb];
        [view addSubview:bb1];
        [view addSubview:cc];
        [view addSubview:cc1];
        [view addSubview:lab];
        
        view.contentSize = CGSizeMake(kWidth,150 + self.knowDetail.kY + self.knowDetail.kH);
        
        [self addSubview:view];
        [self addSubview:clock];

    }
    return self;
}

- (void)setText:(UILabel *)str{
    str.textAlignment = 1;
    str.textColor = [UIColor purpleColor];
    //str.backgroundColor = [UIColor yellowColor];
    str.font = [UIFont systemFontOfSize:14];
}





@end
